/* 
 * File:   App_PowerStapler.h
 * Author: Guichuan.He
  * Created on September 28, 2016, 1:33 PM
 */


#define uint unsigned int
#define uchar unsigned char


#define Work_LED       RC7
#define Encode_HALL_A  RB1
#define Encode_HAll_B  RB2




void App_PowerStapler_Initialize();
void Phase_Standby();
void Phase_ElasticClosure();
void Phase_ElasticOpen();
void Phase_CutSafty();
void Phase_SaftyToOpen();
void Phase_CutReady();
void Phase_Cutting();
void Phase_CutPause();
void Phase_CutEnd();
void Phase_Return();
void Phase_ReturnPause();
void HardWareTest();

extern Motor_Direct_Control(uchar direct);
extern unsigned char  Device_LTC2943_ReadByte(unsigned int address);
extern void Device_LTC2943_WriteByte(unsigned char address,unsigned char dataByte);
extern unsigned int  LTC2943_readByte(unsigned int address);
extern unsigned int Device_LTC2943_ReadVoltage();
extern void Device_LTC2943_Initialize(void);
extern uchar Device_LTC2943_CheckALCC();
extern unsigned char Device_LTC2943_AlertResponse();
extern unsigned int Device_LTC2943_AccumulatedCharge();
extern unsigned int Device_LTC2943_ReadCurrent();
extern void Logic_Initialize_SetDataDefault(void);
extern void AT24C512_writeByte(unsigned char address,unsigned char dataByte);
extern void Device_Indicator_Initialize(unsigned char Status);
extern void Device_Indicator_SetCountLED(uchar CountState);
extern void Device_Indicator_SetBatteryLED(uchar BatteryState);
extern void Device_Indicator_SetDirectorLED(uchar Dir, uchar Mode);
extern unsigned char AT24C512_readByte(unsigned int address);
extern void PIC_Write_Char_To_EEPROM(uint Addr, uchar Data);
extern uchar PIC_Read_Char_From_EEPROM(uint Addr);
extern void Device_MotorOutControl(uint Director);
extern void Device_MotorSetCurrent(int percentage);
extern uchar Device_Trigger_CheckFire();
extern void Device_Indicator_SetLED(uchar SetLED);
extern void Device_MotorReset(uchar nReset);
extern void PIC_Initialize();
extern void GPIO_Initialize();
extern void Device_MotorInitialize();
extern void App_Interrupt_Initialize(void);
extern uchar Device_Trigger_CheckSafe();
extern void Device_LTC2943_Init_AccCharge();
extern void set_time_count(unsigned int time);
extern unsigned int get_time_count(void);
extern void set_red_led(unsigned char led);
extern void  set_green_led(unsigned char led);
extern void  set_yellow_led(unsigned char led);
extern unsigned char Device_PowerCheckALCC(void);
#define Phase_INILIZATION     0
#define Phase_STANDBY         1
#define Phase_ELASTICCLOSURE  2
#define Phase_ELASTICOPEN     3
#define Phase_CUTTING         4
#define Phase_RETURN          5
#define Phase_ERROR           6
#define phase_SAFTY           7
#define phase_SAFTYTOOPEN     8
#define phase_CUTREADY        9
#define phase_CUTEND          10
#define phase_CUTPAUSE        11
#define phase_RETRUNPAUSE     12

uint LED_Flash = 0;
int Charge_Status = 0;
unsigned int warn_flag=0;
int timecounter = 0;
int timecouner_dicharge = 0;
int timecouner_charge = 0;
int timecouner_fullcharge = 0;
uint work_led_flag=0;


struct TimerData
{
    uint Work_LED_Count;
};

struct SterilizationData
{
    uint count;
};

struct MotorControlData
{
    uint ElasticClosureCurrent;
    uint ElasticOpenCurrent;
    uint CuttingCurrent;
    uint ReturnCurrent;
    uint Director;
    uchar Feedback_Director;
    uint Turns_Number;
    uint Feedback_Turns_Number;  
    uchar nFault;
    uchar FeedbackStatus;
};
struct IndicatorData
{
    uchar ForwardLed_Flash;
    uchar BackLED_Flash;
    uchar LED_Status;
};
        
struct PowerStapler
{
    uint Phase_state;
    uint ErrorCode;
    struct SterilizationData Sterilization;
    struct MotorControlData MotorControl; 
    struct TimerData Timer;
    struct IndicatorData Indicator;
};
struct PowerStapler PowerStaplerData;


